﻿@model Telecom.Data.CAPQUANG

@{  AjaxOptions ajaxOpts = new AjaxOptions
    {
        HttpMethod = "post",
        OnComplete = "completedAjaxRequestCQ"
    };
}

<script type="text/javascript">

    function opBeginProcess_loading_window_submit() {

        var valueDate = $('#date_ngay_lap_dat_cap_quang').datebox('getValue');
        if (valueDate == null || valueDate == "") {
            $("#NGAYLD_cap_quang_hidden").val("");
        }

        $("#ContentwindowFunction").mask("Dữ liệu đang xử lý");
    }

    function completedAjaxRequestCQ(obj) {

        var returnObj = eval('(' + obj.responseText + ')');

        if (returnObj.Status == "success") {


            $('#list_cap_quang_TableContainer').jtable('load', { donvi: $("#DONVIQL_cap_quang_hidden").val(), toql: $("#TOQL_cap_quang_hidden").val() , type: "toql" });

            close_window_elements('window_addupdate_add_cap_quang');


        } else {

            $("#ContentwindowFunction").unmask();
            confirmOptionNormal(returnObj.Message);
        }

        return false;

    }

    $(document).ready(function () {

        $("#date_ngay_lap_dat_cap_quang").datebox({
            formatter: formatterDateDDMMYY,
            parser: parserDateDDMMYY,
            onSelect: function (date) {
                $("#NGAYLD_cap_quang_hidden").val(date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear());
            }
        });

        $("#DONVIQ_cap_quang").combobox({

            url: _nameSubDomain + "/Donvi_ToQL/Get_DonVi_To_OnJson_InsertText",
            valueField: "id",
            textField: "text",
            onSelect: function (row) {

                $("#DONVIQL_cap_quang_hidden").val(row.id);
                $("#TOQL_cap_quang").combobox({ url: _nameSubDomain + "/Donvi_ToQL/Get_ToAL_To_OnJson_InsertText?ma=" + row.id });
                $("#vnptSite_Dau_Gan").combogrid({ url: _nameSubDomain + "/Vnpt_Site/listVNPTSITEONDONTOQL?toql=&donvi=" + row.id });
                $("#vnptSite_Dau_xa").combogrid({ url: _nameSubDomain + "/Vnpt_Site/listVNPTSITEONDONTOQL?toql=&donvi=" + row.id });
                $("#TOQL_cap_quang_hidden").val("");

                $("#vnpt_dau_gan_cap_quan_hidden").val(0);
                $("#ODF1_cap_quang_hidden").val(0);
                $("#vnpt_dau_xa_cap_quan_hidden").val(0);
                $("#ODF2_cap_quang_hidden").val(0);

            }

        });

        $("#TOQL_cap_quang").combobox({

            url: _nameSubDomain + "/Donvi_ToQL/Get_ToAL_To_OnJson_InsertText?ma=@Model.DONVIQL",
            valueField: "MA",
            textField: "TEN",
            onSelect: function (row) {

                $("#vnptSite_Dau_Gan").combogrid({ url: _nameSubDomain + "/Vnpt_Site/listVNPTSITEONDONTOQL?toql=" + row.MA + "&donvi=" + $("#DONVIQL_cap_quang_hidden").val() });
                $("#vnptSite_Dau_xa").combogrid({ url: _nameSubDomain + "/Vnpt_Site/listVNPTSITEONDONTOQL?toql=" + row.MA + "&donvi=" + $("#DONVIQL_cap_quang_hidden").val() });
                $("#TOQL_cap_quang_hidden").val(row.MA);

                $("#vnpt_dau_gan_cap_quan_hidden").val(0);
                $("#ODF1_cap_quang_hidden").val(0);
                $("#vnpt_dau_xa_cap_quan_hidden").val(0);
                $("#ODF2_cap_quang_hidden").val(0);

            },

        });

        $("#LOAIPHA_cap_quang").combogrid({

            url: _nameSubDomain + "/TThietbi/ListLoaiPha?mvt=AON",
            idField: 'MA',
            textField: 'TEN',
            fitcomlumm: true,
            columns: [[
                { field: 'TEN', title: 'Tên Pha', width: 150 },
                { field: 'LOAI', title: 'Loại Pha', width: 80 },

            ]],
            onSelect: function (index, row) {

                $("#LOAIPHA_cap_quang_hidden").val(row.MA);

            }

        });

        $("#LOAICAP_cap_quang").combogrid({

            url: _nameSubDomain + "/TCapquang/ListLoaiCap",
            idField: 'MA',
            textField: 'TEN',
            fitcomlumm: true,
            columns: [[
                { field: 'TEN', title: 'Tên', width: 150 },
                { field: 'COLOR', title: 'Màu', width: 80 },

            ]],
            onSelect: function (index, row) {

                $("#LOAICAP_cap_quang_hidden").val(row.MA);
                $("#COLOR_cap_quang_hidden").val(row.COLOR);

            }

        });


        $("#vnptSite_Dau_Gan").combogrid({

            url: _nameSubDomain + "/Vnpt_Site/listVNPTSITEONDONTOQL_LoaiSite?toql=" + $("#TOQL_cap_quang_hidden").val() + "&donvi=" + $("#DONVIQL_cap_quang_hidden").val() + "&LoaiSite=ODF,MXG",
            idField: 'SITEID',
            textField: 'TEN',
            fitcomlumm: true,
            columns: [[
                { field: 'MA', title: 'Mã Site', width: 150 },
                { field: 'DIACHI', title: 'Địa chỉ', width: 260 },
            ]],
            onSelect: function (index, row) {

                $("#ODF1_DAU_GAN").combogrid({ url: _nameSubDomain + "/TCapquang/ListODfBySiteId?siteId=" + row.SITEID });
                $("#vnpt_dau_gan_cap_quan_hidden").val(row.SITEID);
                $("#vnpt_dau_gan_cap_quan_hidden_ma_check").val(row.MA);
                $("#ODF1_cap_quang_hidden").val(0);

            }

        });

        $("#vnptSite_Dau_xa").combogrid({

            url: _nameSubDomain + "/Vnpt_Site/listVNPTSITEONDONTOQL_LoaiSite?toql=" + $("#TOQL_cap_quang_hidden").val() + "&donvi=" + $("#DONVIQL_cap_quang_hidden").val() + "&LoaiSite=ODF,MXG",
            idField: 'SITEID',
            textField: 'TEN',
            fitcomlumm: true,
            columns: [[
                { field: 'MA', title: 'Mã Site', width: 150 },
                { field: 'DIACHI', title: 'Địa chỉ', width: 260 },
            ]],
            onSelect: function (index, row) {

                $("#ODF2_DAU_XA").combogrid({ url: _nameSubDomain + "/TCapquang/ListODfBySiteId?siteId=" + row.SITEID });
                $("#vnpt_dau_xa_cap_quan_hidden").val(row.SITEID);
                $("#vnpt_dau_xa_cap_quan_hidden_ma_check").val(row.MA);
                $("#ODF2_cap_quang_hidden").val(0);

            }

        });

        $("#ODF1_DAU_GAN").combogrid({

            url: _nameSubDomain + "/TCapquang/ListODfBySiteId?siteId=@ViewBag.SiteIdDauGan.SITEID",
            idField: 'ID',
            textField: 'TEN',
            fitcomlumm: true,
            columns: [[
                { field: 'MA', title: 'Mã', width: 80 },
                { field: 'TEN', title: 'Tên', width: 150 },
            ]],
            onSelect: function (index, row) {

                $("#ODF1_cap_quang_hidden").val(row.ID);

            }

        });

        $("#ODF2_DAU_XA").combogrid({

            url: _nameSubDomain + "/TCapquang/ListODfBySiteId?siteId=@ViewBag.SiteIdDauXa.SITEID",
            idField: 'ID',
            textField: 'TEN',
            fitcomlumm: true,
            columns: [[
                { field: 'MA', title: 'Mã', width: 80 },
                { field: 'TEN', title: 'Tên', width: 150 },
            ]],
            onSelect: function (index, row) {

                $("#ODF2_cap_quang_hidden").val(row.ID);

            }

        });

        $("#HANGSX_cap_quang").combogrid({

            url: _nameSubDomain + "/TCapquang/ListLoaiHangSX",
            idField: 'MA',
            textField: 'TEN',
            fitcomlumm: true,
            columns: [[
                { field: 'TEN', title: 'Tên', width: 230 },

            ]],
            onSelect: function (index, row) {

                $("#HANGSX_cap_quang_hidden").val(row.MA);

            }

        });


        $("#LOAISOI_cap_quang").combogrid({

            url: _nameSubDomain + "/TCapquang/ListLoaiSoi",
            idField: 'MA',
            textField: 'TEN',
            fitcomlumm: true,
            columns: [[
                { field: 'TEN', title: 'Tên', width: 230 },

            ]],
            onSelect: function (index, row) {

                $("#LOAISOI_cap_quang_hidden").val(row.MA);

            }

        });

        $("#LAPDAT_cap_quang").combogrid({

            url: _nameSubDomain + "/TCapquang/ListLapDat",
            idField: 'MA',
            textField: 'TEN',
            fitcomlumm: true,
            columns: [[
                { field: 'TEN', title: 'Tên', width: 230 },

            ]],
            onSelect: function (index, row) {

                $("#LAPDAT_cap_quang_hidden").val(row.MA);

            }

        });

    });

    function loadwindow_update_vnptsite_dau_gan_cap_quang() {

        loadwindowOnContent(_nameSubDomain + "/TCapquang/UpdateVNPTSITE_CAPQUANG?SiteId=" + $("#vnpt_dau_gan_cap_quan_hidden").val() + "&LoaiSiteUpCQ=daugan", "window_add_vnpt_site_cap_quang", "Cập nhật VNPT SITE", 620, 600);

    }

    function loadwindow_update_vnptsite_dau_xa_cap_quang() {

        loadwindowOnContent(_nameSubDomain + "/TCapquang/UpdateVNPTSITE_CAPQUANG?SiteId=" + $("#vnpt_dau_xa_cap_quan_hidden").val() + "&LoaiSiteUpCQ=dauxa", "window_add_vnpt_site_cap_quang", "Cập nhật VNPT SITE", 620, 600);

    }

    function loadwindow_update_odf_dau_xa_cap_quang() {

        if (($("#vnpt_dau_xa_cap_quan_hidden").val() == "" || $("#vnpt_dau_xa_cap_quan_hidden").val() == null) && ($("#vnpt_dau_gan_cap_quan_hidden").val() == "" || $("#vnpt_dau_gan_cap_quan_hidden").val() == null)) {

            confirmOptionNormal("Vui lòng chọn trạm đầu gần và đầu xa để lấy mã tự động");
            return false;

        }
        else {

            loadwindowOnContent(_nameSubDomain + "/TCapquang/UpdateOdf?OdfId=" + $("#ODF2_cap_quang_hidden").val() + "&type=odf_dau_xa", "window_add_odf_vnpt_site", "Thêm ODF - VNPT SITE", 600, 350);
        }

    }

    function loadwindow_update_odf_dau_gan_cap_quang() {

        if (($("#vnpt_dau_xa_cap_quan_hidden").val() == "" || $("#vnpt_dau_xa_cap_quan_hidden").val() == null) && ($("#vnpt_dau_gan_cap_quan_hidden").val() == "" || $("#vnpt_dau_gan_cap_quan_hidden").val() == null)) {

            confirmOptionNormal("Vui lòng chọn trạm đầu gần và đầu xa để lấy mã tự động");
            return false;

        }
        else {

            loadwindowOnContent(_nameSubDomain + "/TCapquang/UpdateOdf?OdfId=" + $("#ODF1_cap_quang_hidden").val() + "&type=odf_dau_gan", "window_add_odf_vnpt_site", "Thêm ODF - VNPT SITE", 600, 350);
        }
    }

    function get_ma_name_cap_quang_auto(type) {

        if ($("#DUNGLUONG_CAP_QUANG").val() == "" || $("#DUNGLUONG_CAP_QUANG").val() == null) {
            confirmOptionNormal("Vui lòng nhập dung lượng cáp để lấy mã tự động");
            return false;
        }

        if (($("#vnpt_dau_xa_cap_quan_hidden").val() == "" || $("#vnpt_dau_xa_cap_quan_hidden").val() == null) && ($("#vnpt_dau_gan_cap_quan_hidden").val() == "" || $("#vnpt_dau_gan_cap_quan_hidden").val() == null)) {

            confirmOptionNormal("Vui lòng chọn trạm đầu gần và đầu xa để lấy mã tự động");
            return false;
        }


        if ($("#LAPDAT_cap_quang_hidden").val() == "" || $("#LAPDAT_cap_quang_hidden").val() == null) {
            confirmOptionNormal("Vui lòng chọn lại lắp đặt để lấy mã tự động");
            return false;
        }


        var StringvnptDauGan = $("#vnpt_dau_gan_cap_quan_hidden_ma_check").val().split('.')[1];
        var stringVNPTDauXa = $("#vnpt_dau_xa_cap_quan_hidden_ma_check").val().split('.')[1];


        if (type == "ma") {
            $("#MA_CAP_QUANG").val("");
            $("#MA_CAP_QUANG").val("C." + StringvnptDauGan + "-" + stringVNPTDauXa + "/" + $("#DUNGLUONG_CAP_QUANG").val() + "/" + $("#LAPDAT_cap_quang_hidden").val() + "01");
        }
        else {
            $("#TEN_CAP_QUANG").val("");
            $("#TEN_CAP_QUANG").val("C." + StringvnptDauGan + "-" + stringVNPTDauXa + "/" + $("#DUNGLUONG_CAP_QUANG").val() + "/" + $("#LAPDAT_cap_quang_hidden").val() + "01");
        }


    }


</script>

@using (Ajax.BeginForm("UpdateCapQuang", "TCapquang", null, ajaxOpts, new { enctype = "multipart/form-data" }))
{
    @Html.HiddenFor(model => model.ID)
    @Html.HiddenFor(model => model.ODF1, new { id = "ODF1_cap_quang_hidden" })
    @Html.HiddenFor(model => model.ODF2, new { id = "ODF2_cap_quang_hidden" })
    @Html.HiddenFor(model => model.DONVIQL, new { id = "DONVIQL_cap_quang_hidden" })
    @Html.HiddenFor(model => model.TOQL, new { id = "TOQL_cap_quang_hidden" })
    @Html.HiddenFor(model => model.LOAISOI, new { id = "LOAISOI_cap_quang_hidden" })
    @Html.HiddenFor(model => model.LOAIPHA, new { id = "LOAIPHA_cap_quang_hidden" })
     @Html.HiddenFor(model => model.LOAICAP, new { id = "LOAICAP_cap_quang_hidden" })
    @Html.HiddenFor(model => model.COLOR, new { id = "COLOR_cap_quang_hidden" })
    @Html.HiddenFor(model => model.LAPDAT, new { id = "LAPDAT_cap_quang_hidden" })
    @Html.HiddenFor(model => model.NGAYLD, new { id = "NGAYLD_cap_quang_hidden" })
     @Html.HiddenFor(model => model.HANGSX, new { id = "HANGSX_cap_quang_hidden" })

    <input type="hidden" id="vnpt_dau_xa_cap_quan_hidden" value="@ViewBag.SiteIdDauXa.SITEID" name="vnpt_dau_xa_cap_quan_hidden" />
    <input type="hidden" id="vnpt_dau_gan_cap_quan_hidden" value="@ViewBag.SiteIdDauGan.SITEID" name="vnpt_dau_gan_cap_quan_hidden" />
    <input type="hidden" id="ma_cap_quang_old_hidden" value="@Model.MA" name="ma_cap_quang_old_hidden" />
    <input type="hidden" id="vnpt_dau_gan_cap_quan_hidden_ma_check" value="@ViewBag.VNPTSITE_DAU_GAN.MA" name="vnpt_dau_gan_cap_quan_hidden_ma_check" />
    <input type="hidden" id="vnpt_dau_xa_cap_quan_hidden_ma_check" value="@ViewBag.VNPTSITE_DAU_XA.MA" name="vnpt_dau_xa_cap_quan_hidden_ma_check" />
    
    
    <div id="ContentwindowFunction" class="ContentwindowFunction">
        <table class="tableContentWindowFunction">
            <tr>
                <td>Đơn vị QL
                </td>
                <td>
                    <input class="easyui-combobox" value="@Model.DONVIQL" style="width:250px; height:27px" id="DONVIQ_cap_quang" name="DONVIQ_cap_quang">
                </td>
                <td>Tổ QL
                </td>
                <td>
                    <input class="easyui-combobox" value="@Model.TOQL" style="width:250px; height:27px" id="TOQL_cap_quang" name="TOQL_cap_quang">
                </td>
            </tr>
            <tr>
                <td>Dung lượng
                </td>
                <td style="position:relative;">
                    @Html.TextBoxFor(model => model.DUNGLUONG, new { id="DUNGLUONG_CAP_QUANG", @class = "input_table_function_twocolum" })
                </td>
                <td>Loại cáp
                </td>
                <td>
                    <input class="easyui-combobox" value="@Model.LOAICAP" style="width:250px;" id="LOAICAP_cap_quang" name="LOAICAP_cap_quang">
                </td>
                
            </tr>
            <tr>
                <td>Mã cáp
                </td>
                <td style="position:relative">
                    @Html.TextBoxFor(model => model.MA, new { id="MA_CAP_QUANG", @class = "input_table_function_twocolum_small maTable" })
                    <div style="position: absolute;top: 5px;right: 5px;">
                         <button type="button" onclick="return get_ma_name_cap_quang_auto('ma');" style="padding:3px 0">
                            <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text"></span><span class="l-btn-icon icon-download">&nbsp;</span></span>
                        </button>
                    </div>
                </td>
                <td>Tên cáp
                </td>
                <td style="position:relative">
                    @Html.TextBoxFor(model => model.TEN, new { id="TEN_CAP_QUANG", @class = "input_table_function_twocolum_small" })
                    <div style="position: absolute;top: 5px;right: 5px;">
                         <button type="button" onclick="return get_ma_name_cap_quang_auto('ten');" style="padding:3px 0">
                            <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text"></span><span class="l-btn-icon icon-download">&nbsp;</span></span>
                        </button>
                    </div>
                </td>
            </tr>
            <tr>
                <td>Trạm đầu gần
                </td>
                <td style="position:relative">
                    <input class="easyui-combogrid" value="@ViewBag.SiteIdDauGan.SITEID"  style="width:215px;" id="vnptSite_Dau_Gan" name="vnptSite_Dau_Gan">
                    <div style="position: absolute;top: 5px;right: 5px;">
                         <button type="button" onclick="return loadwindow_update_vnptsite_dau_gan_cap_quang();" style="padding:3px 0">
                            <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text"></span><span class="l-btn-icon icon-edit">&nbsp;</span></span>
                        </button>
                    </div>
                </td>
                <td>Trạm đầu xa
                </td>
                <td style="position:relative">
                    <input class="easyui-combogrid" value="@ViewBag.SiteIdDauXa.SITEID" style="width:215px; " id="vnptSite_Dau_xa" name="vnptSite_Dau_xa">
                    <div style="position: absolute;top: 5px;right: 5px;">
                         <button type="button" onclick="return loadwindow_update_vnptsite_dau_xa_cap_quang();" style="padding:3px 0">
                            <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text"></span><span class="l-btn-icon icon-edit">&nbsp;</span></span>
                        </button>
                    </div>
                </td>
            </tr>
             <tr>
                 <td>Odf đầu gần
                </td>
                <td style="position:relative">
                    <input class="easyui-combogrid" value="@Model.ODF1" style="width:215px;" id="ODF1_DAU_GAN" name="ODF1_DAU_GAN">
                    <div style="position: absolute;top: 5px;right: 5px;">
                         <button type="button" onclick="return loadwindow_update_odf_dau_gan_cap_quang();" style="padding:3px 0" >
                            <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text"></span><span class="l-btn-icon icon-edit">&nbsp;</span></span>
                        </button>
                    </div>
                </td>
                <td>Odf đầu xa
                </td>
                <td style="position:relative">
                    <input class="easyui-combogrid" value="@Model.ODF2" style="width:215px; " id="ODF2_DAU_XA" name="ODF2_DAU_XA">
                    <div style="position: absolute;top: 5px;right: 5px;">
                         <button type="button" onclick="return loadwindow_update_odf_dau_xa_cap_quang();" style="padding:3px 0" >
                            <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text"></span><span class="l-btn-icon icon-edit">&nbsp;</span></span>
                        </button>
                    </div>
                </td>
                
            </tr>
            <tr>
                <td>Chiều dài
                </td>
                <td style="position:relative;">
                    @Html.TextBoxFor(model => model.CHIEUDAI, new { id="CHIEUDAI_CAP_QUANG", @class = "input_table_function_twocolum" })
                </td>
                <td>Loại pha
                </td>
                <td>
                    <input class="easyui-combobox" value="@Model.LOAIPHA" style="width:250px;" id="LOAIPHA_cap_quang" name="LOAIPHA_cap_quang">
                </td>
            </tr>
            <tr>
                <td>Hãng SX
                </td>
                <td>
                    <input class="easyui-combobox" value="@Model.HANGSX" style="width:250px;" id="HANGSX_cap_quang" name="HANGSX_cap_quang">
                </td>
                <td>Loại sợi
                </td>
                <td>
                    <input class="easyui-combobox" value="@Model.LOAISOI" style="width:250px;" id="LOAISOI_cap_quang" name="LOAISOI_cap_quang">
                </td>
            </tr>
            <tr>
                <td>Loại lắp đặt
                </td>
                <td>
                    <input class="easyui-combobox" value="@Model.LAPDAT" style="width:250px;" id="LAPDAT_cap_quang" name="LAPDAT_cap_quang">
                </td>
                <td>Ngày lắp đặt
                </td>
                <td>
                    <input id="date_ngay_lap_dat_cap_quang" value="@Model.NGAYLD" style="width:250px;height:27px" />
                </td>
            </tr>
            <tr>
                <td>Ghi chú
                </td>
                <td colspan="3">
                    @Html.TextAreaFor(model => model.GHICHU, new { @class = "input_table_function_area_two_cloum" })
                </td>
            </tr>
        </table>
        <div style="height: 20px"></div>
        <div class="footer_submit" style="margin-top: 0px; text-align: center">
            <button type="submit" onclick="return opBeginProcess_loading_window_submit(); ">
                <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">Cập nhật cáp quang</span><span class="l-btn-icon icon-add">&nbsp;</span></span>
            </button>
            <button type="button" onclick="return close_window_elements('window_addupdate_add_cap_quang');">
                <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">Hủy bỏ</span><span class="l-btn-icon icon-remove">&nbsp;</span></span></button>
        </div>
    </div>
    

}